package co.fitstart.admin.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import com.demo2do.core.persistence.annotation.Dynamic;

import co.fitstart.admin.dao.CoachDao;
import co.fitstart.admin.dao.CoachRestCalendarDao;
import co.fitstart.admin.dao.CourseScheduleDao;
import co.fitstart.admin.entity.report.HourlySchedule;
import co.fitstart.admin.service.ScheduleReportService;
import co.fitstart.entity.principal.Principal;
import co.fitstart.entity.site.Site;

/**
 * 
 * @author Ysy
 *
 */
@Service("scheduleReportService")
public class ScheduleReportServiceImpl implements ScheduleReportService {
    
    @Dynamic
    private CoachDao coachDao;
    
    @Dynamic
    private CourseScheduleDao courseScheduleDao;
    
    @Dynamic
    private CoachRestCalendarDao coachRestCalendarDao;

    /*
     * (non-Javadoc)
     * @see co.fitstart.admin.service.ScheduleReportService#listCoachNames(co.fitstart.entity.site.Site)
     */
    public List<String> listCoachNames(Site site) {
        return coachDao.listCoachName(site);
    }
    

    /*
     * (non-Javadoc)
     * @see co.fitstart.admin.service.ScheduleReportService#listCourseSchedule(java.util.Date, java.util.Date, co.fitstart.entity.site.Site)
     */
    public List<HourlySchedule> listCourseSchedule(Date beginDate, Date endDate, Site site) {
        List<HourlySchedule> result = new ArrayList<HourlySchedule>();
        List<Long> coachIds = coachDao.coacheIds(site.getManager());
        if(CollectionUtils.isNotEmpty(coachIds)) {
            result = courseScheduleDao.listCourseSchedule(beginDate, endDate, coachIds);
        }
        
        return result;
    }

    /*
     * (non-Javadoc)
     * @see co.fitstart.admin.service.ScheduleReportService#listRsetSchedule(java.util.Date, java.util.Date, co.fitstart.entity.site.Site)
     */
    public List<HourlySchedule> listRestSchedule(Date beginDate, Date endDate, Site site) {
        List<HourlySchedule> hourlySchedules = new ArrayList<HourlySchedule>();
        Principal manager = site.getManager();
        List<Long> coachIds = coachDao.coacheIds(manager);
        
        if(CollectionUtils.isNotEmpty(coachIds)){
            hourlySchedules = coachRestCalendarDao.listRestSchedule(beginDate, endDate, coachIds);
        }
            
        return hourlySchedules;
    }
}
